package com.xiaoximen;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class SignUpActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_signup);
		
		init();
	}
	
	private void init() {
		findViewById(R.id.signup_confirm_button).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (checkName() && checkPhone()) {
					Intent intent = new Intent(getApplicationContext(), MainActivity.class);
					startActivity(intent);
					finish();
				}
			}
		});
	}
	
	private boolean checkName() {
		if (((EditText) findViewById(R.id.signup_name_edit)).getText().toString()
				.equals("")) {
			new AlertDialog.Builder(this).setTitle(R.string.warning)
				.setMessage(R.string.warning_name_empty)
				.setPositiveButton(R.string.confirm, null)
				.show();
			return false;
		} else {
			return true;
		}
	}
	
	private boolean checkPhone() {
		String phone = ((EditText) findViewById(R.id.signup_phone_edit)).getText().toString();
		if (phone.equals("") || !phone.startsWith("1") || phone.length() != 11) {
			new AlertDialog.Builder(this).setTitle(R.string.warning)
				.setMessage(R.string.warning_phone_invalid)
				.setPositiveButton(R.string.confirm, null)
				.show();
			return false;
		} else {
			return true;
		}
	}
}
